package com.example.image.glide

import android.content.Context
import com.bumptech.glide.GlideBuilder
import com.bumptech.glide.annotation.GlideModule
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory
import com.bumptech.glide.load.engine.cache.LruResourceCache
import com.bumptech.glide.load.engine.cache.MemorySizeCalculator
import com.bumptech.glide.module.AppGlideModule
/**
 * 使用GlideModule来配置Glide内存和磁盘缓存的大小
 * */
@GlideModule
class GlideModule : AppGlideModule(){

    override fun applyOptions(context: Context, builder: GlideBuilder) {
        //获取内存计算器
        var memorySizeCalculator = MemorySizeCalculator.Builder(context).build()

        //计算App的1/4的内存大小
        var glideMemorySize =memorySizeCalculator.memoryCacheSize/8L

        //修改Glide的内存缓存大小
        builder.setMemoryCache(LruResourceCache(glideMemorySize))

        //修改Glide的磁盘缓存大小
        builder.setDiskCache(InternalCacheDiskCacheFactory(context,"imgCache",200*1024*1024))



    }



}